package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.List;

@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    public Result<Category> insert(@RequestBody CategoryDTO categoryDTO){
        return categoryService.insert(categoryDTO);
    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @PutMapping()
    public Result update(@RequestBody CategoryDTO categoryDTO){

        return categoryService.update(categoryDTO);
    }

    /**
     * 分类分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> selectPage(CategoryPageQueryDTO categoryPageQueryDTO){

        return categoryService.selectPage(categoryPageQueryDTO);
    }

    /**
     * 启用禁用
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,Long id){
        categoryService.updateStatus(status,id);
        return Result.success();
    }

    /**
     * 根据类型查询
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result<List<Category>> selectByType(Integer type){
        return categoryService.selectByType(type);
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteById(Long id){
        return categoryService.deleteById(id);
    }


}
